package code.google.jcontainer.test.extend;

import code.google.jcontainer.AbstractContainer;
import code.google.jcontainer.ContainerFactory;
import code.google.jcontainer.event.ComponentInvocationEvent;
import code.google.jcontainer.event.ContainerListener;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>, 2009-12-30 17:33:41
 */
public class ExtendedTestCase {

    private static AbstractContainer extendedContainer;

    @BeforeClass
    public static void setup(){
        // get my simple container by name
        extendedContainer = ContainerFactory.scanPackages("code.google.jcontainer.test").getContainer("ExtendedContainer");
        // add listener
        extendedContainer.addListener(new ContainerListener(){
            
            public void onComponentMethodInvoke(ComponentInvocationEvent componentInvocationEvent) {
                System.out.println("onComponentMethodInvoke");
            }

            public void onComponentMethodReturn(ComponentInvocationEvent componentInvocationEvent) {
                System.out.println("onComponentMethodReturn");
            }
        });
    }

    @Test
    public void testDefaultWord() {
        // get the simple component by name
        ExtendedTestBean extendedTestBean = (ExtendedTestBean) extendedContainer.getComponent("ExtendedTestBean");
        // invoke sayHello
        Assert.assertEquals(extendedTestBean.echo("Hello, World!"), ExtendedContainer.DEFAULT_WORD);
    }

}
